mapa = []
entity = []
def isIn(string,l):
    for i in l:
        if i == string:
            return True
            break
    return False
while True:
    choice = raw_input("Map:\>")
    if str(choice) == "fill":
        start = raw_input("Start(x,y):")
        start = start.split(",")
        end = raw_input("End(x,y):")
        end = end.split(",")
        texture = input("With:")
        if isIn(texture,textures):
            pass
        else:
            textures.append(texture)
        col = raw_input("Collision:")
        for x in range(int(start[0]),int(end[0])):
            for y in range(int(start[1]),int(end[1])):
                mapa[x].pop(y)
                mapa[x].insert(y,(str(x)+"x"+str(y),texture,col))
    elif str(choice) == "draw":
        for x in range(0,int(size[0])):
            for y in range(0,int(size[1])):
                if mapa[x][y][2]:
                    print "*"
                else:
                    print "|"
    elif str(choice) == "help":
        print "fill,change,draw,render,help,create,edit"
    elif str(choice) == "entity":
        pos = raw_input("Pos(x,y):")
        print pos
        name = raw_input("Name:")
        par  = raw_input("Parameters(Name:Value):")
        entity.append((str(pos),str(name),str(par)))
    elif str(choice) == "change":
        pos = raw_input("Pos(x,y):")
        pos = pos.split(",")
        texture = input("With:")
        col = raw_input("Collision:")
        mapa[int(pos[0])].pop(int(pos[1]))
        mapa[int(pos[0])].insert(int(pos[1]),(str(pos[0])+"x"+str(pos[1]),texture,col))
    elif str(choice) == "render":
        name = raw_input("Name:")
        mapFile = open(str(name),"w")
        mapFile.write(str(entity)+";")
        mapFile.write(str(textures)+";")
        mapFile.write(str(size[0])+"x"+str(size[1])+";")
        for x in range(0,int(size[0])):
            for y in range(0,int(size[1])):
                mapFile.write(str(mapa[x][y])+";")
        mapFile.close()
    elif str(choice) == "create":
        size = raw_input("Size(width,height):")
        size = size.split(",")
        textures = ["grass.png"]
        size = [int(size[0])+1,int(size[1])+1]
        for x in range(0,int(size[0])):
            mapa.append([])
            for y in range(0,int(size[1])):
                mapa[x].append((str(x)+"x"+str(y),"grass.png",False))
    else:
        print "WROOOOOOOOOOOOONG command"
